home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-15 | 9.0 KB | 356 lines | [TEXT/KAHL] |
- /*
- * ShapeSetup.c
- *
- * Robert Dierkes, April 26, 1993
- *
- * Change History:
- *
- * 4/93 ??? New
- * 4/96 bob Updated #includes to support changed GX Library names.
- * Changed fixed to Fixed.
- * Changed boolean to Boolean.
- * Added the copyright info.
- *
- *
- * © Apple Computer, Inc. 1990 - 1996 All rights reserved
- *
- */
-
-
- #undef MAC_HEADERS
-
-
- /*------------------*/
- /* Include Files */
- /*------------------*/
- #ifndef MAC_HEADERS
- #include <Memory.h>
- #include <Windows.h>
- #include <Controls.h>
- #endif MAC_HEADERS
-
- #include <GXGraphics.h>
- #include <GXMath.h>
- #include "GraphicsLibraries.h"
- #include "FontLibrary.h"
-
- #include "ShapeSetup.h"
-
-
- /*----------------------*/
- /* Global Declarations */
- /*----------------------*/
-
-
- /*------------------------------*/
- /* External Declarations */
- /*------------------------------*/
-
-
- /*------------------------------*/
- /* Local ProtoTypes */
- /*------------------------------*/
-
-
- Boolean
- CreateShapesFrame (WindowPtr pWindow, register long numRows, register long numCols, gxShape *pBoxSet)
- {
- #define kSixteenthInch (IntToFixed (4) + kFixOneHalf)
-
- gxRectangle bounds;
- register
- long r, c;
- gxShape box;
- Fixed side,
- left,
- top;
-
- if (numRows == 0 || numCols == 0)
- {
- DebugStr ("\pCreateShapesFrame: Number of rows or columns is zero");
- return (false);
- }
-
- /* Find side of each enclosing box */
- side = FixedDivide (IntToFixed (pWindow->portRect.bottom - pWindow->portRect.top),
- IntToFixed (numCols)) - kSixteenthInch;
-
- *pBoxSet = GXNewShape (gxEmptyType);
- for (r = 0, top = kSixteenthInch + (kSixteenthInch>>1); r < numRows; r++, top += side)
- {
- for (c = 0, left = kSixteenthInch + (kSixteenthInch>>1); c < numCols; c++, left += side)
- {
- box = NewShape4 (gxRectangleType, left, top, left + side, top + side);
- GXInsetShape (box, kSixteenthInch);
- GXSetShapeFill (box, gxEvenOddFill);
- AddToShape (*pBoxSet, box);
- GXDisposeShape (box);
- }
- }
- SetShapeCommonColor (*pBoxSet, grayish + silver);
-
- return (true);
- }
-
-
- Boolean
- CreateHitTestShapes (WindowPtr pWindow, gxShape **h1stHitShape, gxShape *pBoxSet, register long shapeCount)
- {
- gxShape *pShape;
- register
- long shapeNum;
- gxRectangle bounds;
-
- if (shapeCount <= 0)
- {
- DebugStr ("\pCreateHitTestShapes: Number of shapes is <= zero");
- return (false);
- }
-
- if (h1stHitShape == nil)
- {
- DebugStr ("\pCreateHitTestShapes: Shape list handle is nil");
- return (false);
- }
-
- /* Allocate space for hit shapes */
- *h1stHitShape = pShape = (gxShape *) NewPtr (shapeCount * sizeof (gxShape));
- if (*h1stHitShape == nil)
- {
- DebugStr ("\pCreateHitTestShapes: NewPtr for shapes failed");
- return (false);
- }
-
- for (shapeNum = 0; shapeNum < shapeCount; shapeNum++, pShape++)
- {
- switch (shapeNum)
- {
- case kTrapizoidPolygon:
- *pShape = NewShape4 (gxRectangleType, 0, 0, kHalfInch, kHalfInch);
- SkewShapeAboutCenter (*pShape, -kFixOneHalf, 0);
- SetShapeCommonColor (*pShape, light + blue);
- break;
-
- case kOvalPath:
- bounds.left =
- bounds.top = 0;
- bounds.right =
- bounds.bottom = kHalfInch;
- *pShape = NewOval (&bounds);
-
- GXSetShapeFill (*pShape, gxClosedFrameFill);
- GXSetShapePen (*pShape, IntToFixed (15));
- SetShapeCommonColor (*pShape, rose_madder);
- break;
-
- case kArrowPolygon:
- {
- Fixed arrow[] = {1L, 7L, 0, IntToFixed (5),
- 0, IntToFixed (15),
- IntToFixed (12), IntToFixed (14),
- IntToFixed (10), IntToFixed (20),
- IntToFixed (27), IntToFixed (10),
- IntToFixed (10), 0,
- IntToFixed (12), IntToFixed (6)};
- gxJoinRecord joinRec;
-
- *pShape = GXNewPolygons ((gxPolygons *) arrow);
-
- joinRec.attributes = gxCurveJoin;
- joinRec.join = nil;
- joinRec.miter = 0;
- GXSetShapeJoin (*pShape, &joinRec);
- GXSetShapeFill (*pShape, gxClosedFrameFill);
- GXSetShapePen (*pShape, IntToFixed (12));
-
- RotateShapeAboutCenter (*pShape, IntToFixed (-45));
- SetShapeCommonColor (*pShape, turquoise);
- }
- break;
-
- case kPatternedPolygon:
- {
- Fixed star[] = {1L, 5L, IntToFixed (3), IntToFixed (18),
- IntToFixed (9), 0,
- IntToFixed (15),IntToFixed (18),
- 0, IntToFixed (6),
- IntToFixed (18),IntToFixed (6)};
- gxPatternRecord patternRec;
-
- *pShape = NewShape4 (gxRectangleType, 0, 0, kHalfInch, kHalfInch);
- RotateShapeAboutCenter (*pShape, IntToFixed (-6));
- SetShapeCommonColor (*pShape, gxWhite);
-
- patternRec.pattern = GXNewPolygons ((gxPolygons *) star);
- GXSetShapeFill (patternRec.pattern, gxWindingFill);
- patternRec.u.x = kQuarterInch;
- patternRec.u.y = -kQuarterInch;
- patternRec.v.x = kQuarterInch;
- patternRec.v.y = kEigthInch;
- GXSetShapePattern (*pShape, &patternRec);
- GXDisposeShape (patternRec.pattern);
- }
- break;
-
- case kWordGlyphs:
- {
- #define kText "GX"
- gxPoint position = {0, 0};
-
- *pShape = NewCString (kText, &position);
- GXSetShapeType (*pShape, gxGlyphType);
- GXSetShapeTextSize (*pShape, IntToFixed (66));
- SetStyleCNamedFont (GXGetShapeStyle (*pShape), "Hoefler Italic");
- SetShapeCommonColor (*pShape, indigo);
- }
- break;
-
- case kArchCurve:
- {
- Fixed arch[] = { 0, kHalfInch,
- kEigthInch, 0,
- kQuarterInch, kHalfInch};
-
- *pShape = GXNewCurve ((gxCurve *) arch);
- GXSetShapePen (*pShape, IntToFixed (20));
- SetShapeCommonColor (*pShape, light + maroon); /* light + violet */
- ScaleShapeAboutCenter (*pShape, 5 * fixed1, 3 * fixed1);
- }
- break;
-
- case kCapsLine:
- {
- #define kFixOneQuarter (fixed1 >> 2)
- #define kFix3Quarters ((3 * fixed1) >> 2)
-
- Fixed star[] = {1L, 5L, -fixed1-kFixOneQuarter, -3*fixed1+kFixOneQuarter,
- -fixed1-kFixOneQuarter, 2*fixed1+kFixOneHalf,
- fixed1+kFix3Quarters, -2*fixed1,
- -3*fixed1, 0,
- fixed1+kFix3Quarters, fixed1+kFix3Quarters};
- gxCapRecord cap;
- gxRectangle endRect;
-
- *pShape = NewShape4 (gxLineType, fixed1, 0, 0, fixed1);
- GXSetShapePen (*pShape, IntToFixed (8));
- SetShapeCommonColor (*pShape, viridian_light);
-
- endRect.left = 0;
- endRect.top = kFix3Quarters;
- endRect.right = 2 * kFix3Quarters;
- endRect.bottom = -kFix3Quarters;
- cap.endCap = GXNewRectangle (&endRect);
- cap.startCap = GXNewPolygons ((gxPolygons *) star);
-
- cap.attributes = 0;
- GXSetShapeCap (*pShape, &cap);
- GXDisposeShape (cap.startCap);
- GXDisposeShape (cap.endCap);
- }
- break;
-
- case kDashedOvalPath:
- {
- gxDashRecord dashRec;
-
- bounds.left =
- bounds.top = 0;
- bounds.right =
- bounds.bottom = kQuarterInch;
-
- dashRec.attributes = gxBreakDash + gxAutoAdvanceDash;
- dashRec.dash = NewOval (&bounds);
- dashRec.advance = kHalfInch;
- dashRec.phase = 0;
- dashRec.scale = kQuarterInch;
-
- bounds.left =
- bounds.top = 0;
- bounds.right =
- bounds.bottom = kHalfInch + kEigthInch;
- *pShape = NewOval (&bounds);
-
- GXSetShapeDash (*pShape, &dashRec);
- GXSetShapeFill (*pShape, gxClosedFrameFill);
- GXSetShapeStyleAttributes (*pShape, gxOutsideFrameStyle);
- GXSetShapePen (*pShape, kQuarterInch);
- SetShapeCommonColor (*pShape, light + apple_yellow);
- GXDisposeShape (dashRec.dash);
- }
- break;
-
- case kJoinPath:
- {
- Fixed spokes[] = {1L, 8L, 0x55000000, 0, IntToFixed (4),
- IntToFixed (4), IntToFixed (4),
- IntToFixed (4), 0,
- IntToFixed (4), IntToFixed (4),
- IntToFixed (8), IntToFixed (4),
- IntToFixed (4), IntToFixed (4),
- IntToFixed (4), IntToFixed (8),
- IntToFixed (4), IntToFixed (4)};
- *pShape = GXNewPaths ((gxPaths *) spokes);
- SetShapeCommonColor (*pShape, light + orange);
- }
- break;
- }
-
- if (*pShape)
- {
- GXGetShapeBounds (*pBoxSet, shapeNum + 1, &bounds);
-
- if (shapeNum == kWordGlyphs)
- GXMoveShapeTo (*pShape, bounds.left + kEigthInch, bounds.bottom - kHalfInch - kEigthInch);
- else if (shapeNum == kArchCurve)
- CenterShape (*pShape, &bounds);
- else
- GXSetShapeBounds (*pShape, &bounds);
-
- if (shapeNum == kTrapizoidPolygon ||
- shapeNum == kOvalPath ||
- shapeNum == kPatternedPolygon ||
- shapeNum == kDashedOvalPath)
- GXInsetShape (*pShape, kQuarterInch);
-
- if (shapeNum == kArrowPolygon)
- ScaleShapeAboutCenter (*pShape, kFixOneHalf + (kFixOneHalf >> 1), kFixOneHalf + (kFixOneHalf >> 1));
-
- if (shapeNum == kCapsLine)
- ScaleShapeAboutCenter (*pShape, kFixOneHalf, kFixOneHalf);
-
- if (shapeNum == kJoinPath)
- ScaleShapeAboutCenter (*pShape, 7 * (kFixOneHalf >> 2), 7 * (kFixOneHalf >> 2));
-
- GXCacheShape (*pShape);
- }
- }
-
- return (true);
- }
-
-
- void
- DisposeHitTestShapes (gxShape **h1stHitShape, gxShape *pBoxes)
- {
- register
- gxShape *pShape;
- long shapeCount;
-
- if (pBoxes && *pBoxes)
- {
- if (h1stHitShape && *h1stHitShape)
- {
- shapeCount = GXCountShapeContours (*pBoxes);
- pShape = *h1stHitShape + shapeCount - 1;
-
- while (shapeCount--)
- DisposeShapeAt (pShape--);
-
- DisposePtr ((Ptr) *h1stHitShape);
- *h1stHitShape = nil;
- }
-
- DisposeShapeAt (pBoxes);
- }
- }
-